<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <style>
      button {
        height: 50px;
        width: 150px;
        border: 2px solid #aaa;
        background: rgb(112, 171, 248);
        color: #fff;
        border-radius: 25px;
        font-size: 22px;
      }
    </style>
  </head>
  <body>
    <button id="red">红色</button>
    <button id="yellow">黄色</button>
    <button id="green">绿色</button>
    <button id="pink">粉色</button>
    <script>
      // 第一步：获取元素  body还有按钮
      //   通过ByTagName标签名获取，数组形式获取
      var oBody = document.getElementsByTagName("body")[0];
      var btnRed = document.getElementById("red");
      var btnYellow = document.getElementById("yellow");
      var btnGreen = document.getElementById("green");
      var btnPink = document.getElementById("pink");
      //   console.log(btnRed);

      function color(color) {
        oBody.style.background = color;
      }

      btnRed.onclick = function () {
        color("red");
      };
      btnYellow.onclick = function () {
        color("yellow");
      };
    </script>
  </body>
</html>
